﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CUiC3DProcessesGrid
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using C1.Win.C1FlexGrid;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui48;


namespace DnProcessSimulateCommands;

internal class CUiC3DProcessesGrid : TxFlexGridExtension
{
  private const int OPERATIONS_NAME_COL_NUM = 0;
  internal const string ITEM_STYLE = "Item";
  internal const string ITEM_SELECTED_STYLE = "SelectedItem";
  internal const string ITEM_STEP_STYLE = "StepItem";
  internal const string ITEM_STEP_SELECTED_STYLE = "StepSelectedItem";
  private IContainer components;

  internal CUiC3DProcessesGrid() => this.InitializeComponent();

  internal CUiC3DProcessesGrid(IContainer container)
  {
    container.Add((IComponent) this);
    this.InitializeComponent();
  }

  private void CreateColumnStyles()
  {
    ((C1FlexGridBase) this).DrawMode = (DrawModeEnum) 1;
    CellStyle cellStyle1 = ((C1FlexGridBase) this).Styles.Normal;
    cellStyle1 = ((C1FlexGridBase) this).Styles.Add("Item", ((C1FlexGridBase) this).Styles.Focus);
    CellStyle cellStyle2 = ((C1FlexGridBase) this).Styles.Add("SelectedItem", ((C1FlexGridBase) this).Styles.Focus);
    cellStyle2.BackColor = SystemColors.Highlight;
    cellStyle2.ForeColor = SystemColors.HighlightText;
    ((C1FlexGridBase) this).Styles.Add("StepItem", ((C1FlexGridBase) this).Styles.Focus).Font = new Font(((Control) this).Font, FontStyle.Italic);
    CellStyle cellStyle3 = ((C1FlexGridBase) this).Styles.Add("StepSelectedItem", ((C1FlexGridBase) this).Styles.Focus);
    cellStyle3.Font = new Font(((Control) this).Font, FontStyle.Italic);
    cellStyle3.BackColor = SystemColors.Highlight;
    cellStyle3.ForeColor = SystemColors.HighlightText;
  }

  internal void Initialize(ref List<CApC3DProcessNodeData> nodeOperationsList)
  {
    this.CreateColumnStyles();
    foreach (CApC3DProcessNodeData dprocessNodeData in nodeOperationsList)
    {
      Row row = ((C1FlexGridBase) this).Rows.Add();
      row[0] = (object) ((ITxObject) dprocessNodeData.NodeObject).Name;
      dprocessNodeData.GridRow = row;
      row.IsNode = true;
      ((RowCol) row).UserData = (object) dprocessNodeData;
      Node node = row.Node;
      node.Level = dprocessNodeData.NodeLevel;
      ((TxFlexGrid) this).SetImageByObject(((RowCol) node.Row).Index, 0, (ITxObject) dprocessNodeData.NodeObject);
      this.SetProcessNodeStyle(row);
    }
  }

  internal void SetProcessNodeStyle(Row row)
  {
    if (!(((RowCol) row).UserData is CApC3DProcessNodeData userData))
      return;
    if (((RowCol) row).Selected)
    {
      if (userData.IsStep)
        this.SetRowStyle(row, "StepSelectedItem");
      else
        this.SetRowStyle(row, "SelectedItem");
    }
    else if (userData.IsStep)
      this.SetRowStyle(row, "StepItem");
    else
      this.SetRowStyle(row, "Item");
  }

  internal void SetRowStyle(Row row, string style)
  {
    CellStyle style1 = ((C1FlexGridBase) this).Styles[style];
    ((RowCol) row).Style = style1;
  }

  internal ArrayList GetProcesses(int level)
  {
    ArrayList processes = new ArrayList();
    if (level == -1)
    {
      foreach (Row row in (IEnumerable) ((C1FlexGridBase) this).Rows.Selected)
      {
        if (((RowCol) row).Index > 0 && ((RowCol) row).UserData != null && ((RowCol) row).UserData is CApC3DProcessNodeData userData)
          processes.Add((object) userData);
      }
    }
    else
    {
      foreach (Row row in (IEnumerable) ((C1FlexGridBase) this).Rows)
      {
        if (row.IsNode && row.Node.Level == level && ((RowCol) row).UserData is CApC3DProcessNodeData userData)
          processes.Add((object) userData);
      }
    }
    return processes;
  }

  internal void RefreshAllRowsStyle()
  {
    foreach (Row row in (IEnumerable) ((C1FlexGridBase) this).Rows)
    {
      if (((RowCol) row).Index > 0 && ((RowCol) row).UserData != null)
        this.SetProcessNodeStyle(row);
    }
  }

  private void CUiC3DProcessesGrid_OwnerDrawCell(object sender, OwnerDrawCellEventArgs e)
  {
    this.SetProcessNodeStyle(((C1FlexGridBase) this).Rows[e.Row]);
  }

  protected virtual void MarkAllSelected()
  {
    foreach (Row row in (IEnumerable) ((C1FlexGridBase) this).Rows.Selected)
    {
      if (((RowCol) row).Index > 0 && ((RowCol) row).UserData != null)
        this.SetProcessNodeStyle(row);
    }
  }

  protected virtual void ClearAllMarked() => this.RefreshAllRowsStyle();

  protected virtual void Dispose(bool disposing)
  {
    if (disposing && this.components != null)
      this.components.Dispose();
    ((TxFlexGrid) this).Dispose(disposing);
  }

  private void InitializeComponent()
  {
    ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (CUiC3DProcessesGrid));
    ((ISupportInitialize) this).BeginInit();
    ((Control) this).SuspendLayout();
    ((C1FlexGridBase) this).AllowEditing = false;
    ((C1FlexGridBase) this).AllowSorting = (AllowSortingEnum) 0;
    componentResourceManager.ApplyResources((object) this, "$this");
    ((C1FlexGridBase) this).ExtendLastCol = true;
    ((C1FlexGridBase) this).HighLight = (HighLightEnum) 0;
    ((RowColCollection) ((C1FlexGridBase) this).Rows).Count = 1;
    ((C1FlexGridBase) this).SelectionMode = (SelectionModeEnum) 7;
    ((C1FlexGridBase) this).Tree.Column = 0;
    ((C1FlexGridBase) this).OwnerDrawCell += new OwnerDrawCellEventHandler(this.CUiC3DProcessesGrid_OwnerDrawCell);
    ((ISupportInitialize) this).EndInit();
    ((Control) this).ResumeLayout(false);
  }
}
